home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 November / Macworld (1999-11).dmg / Shareware World / Info / For Developers / Smile1.6.6.sea / Smile1.6.6 / Smile ƒ / Help files / Scripts in text windows < prev    next >
Text File  |  1999-08-17  |  4KB  |  74 lines

  1. Scripts In Text Windows
  2.  
  3.  
  4. Debugging within Smile is accomplished mainly through use its text windows.  It is thus important that you become familiar with the utilization of  text windows for writing/editing/debugging scripts. For a quick start, control-click try it now.
  5.  
  6.  
  7. The basics
  8.  
  9. • Text windows offer a favorable environment for editing and debugging scripts. Scripts can be executed on a line-by-line basis, or in selected blocks. For a quick start through an example, see debugging a script.
  10.  
  11. • A text window can also serve as a calculator for both simple and complex mathematical functions.
  12.  
  13. • To execute a script line (or a mathematical expression), position the cursor somewhere on the line, and press the Enter key (in the numeric keypad). (Alternately, select the entire line then press the Enter key.). Caution ! Do not press the carriage return key ( ) instead.
  14.  
  15. To execute a block of script lines, select the entire block, then press the Enter key.
  16.  
  17. As a substitute (in particular if your keyboard does not have the Enter key), you can on most machines use the combination ctrl-C.
  18.  
  19. • When you press the Enter key in any text window, the current paragraph or the selected text is compiled, and executed if it is executable.
  20.  
  21. • Pressing the Enter key initiates an attempt to compile and execute the selected text.  The result returned by the execution is appended at the end of the text, optionally preceded by double dashes ("--"), depending on the preference setting. See "Preferences" dialog, and see output windows about redirecting the result to other windows.
  22.  
  23.  
  24. Debugging in text windows : some hints
  25.  
  26. • Scope of variables
  27. A variable can be made available from anywhere while Smile is open. To accomplish this, run (compile and execute) the line(s) of script which include the variable. If the variable is included within a handler, a "global" declaration must be used to extend its scope outside the handler. 
  28.  
  29. • Scope of handlers
  30. After a handler is compiled,  it becomes available from anywhere until you quit Smile. When debugging a script line which calls a particular handler, you can compile this handler in any text window to make it universally available. 
  31.  
  32. • Global variables
  33. Smile contains some global variables. To create and access a global variable, use the "my" prefix. Global variables are saved automatically when the user quits Smile. 
  34.  
  35. • Debugging a repeat loop
  36. Additional lines must be used to debug the script inside of a repeat loop. The additional lines simulate the "repeat" operation. 
  37.  
  38. Select, then run the following three lines : 
  39. ----------------------------
  40. repeat with i from 1 to 5
  41.     display dialog i * pi
  42. end repeat
  43. ----------------------------
  44.  
  45. and observe the operation of a standard repeat loop. Note that this example is simple, and a real-life case may be more complex and  include many lines of script within the "repeat" structure. 
  46.  
  47. To debug the above script for a specific value of i, write and execute the following line :
  48. ----------------------------
  49. set i to 3 -- using "3" for example
  50. ----------------------------
  51.  
  52. before you execute "display dialog i*pi" in order to simulate a certain count of the loop.
  53.  
  54. • Debugging an "if" statement
  55. To debug "if" branching, you must simulate it. First, test "manually" the condition. Suppose you are debugging a script which contains the following block.
  56. ----------------------------
  57. if theName is "Stop" then
  58. -- do something like stopping
  59. else
  60. -- do something else
  61. end
  62. ----------------------------
  63.  
  64. Select the condition [theName is "Stop"]. Press the Enter key. The result will be true or false (assuming that theName has been assigned a value prior to pressing the Enter key). (See output windows if you are not familiar with where the result true / false will be displayed). Then, to simulate the "if" statement, execute the block of lines according to the true / false result of the test.
  65.  
  66. • Adding some debug output
  67. One convenient way of keeping track of what lines have run is to insert here and there some "msg" commands (see Routines). "msg(someString)" will write the string someString to the "Worksheet", after having opened it if necessary.
  68. Of course, you must send the "msg" request to Smile. When you run a script from Smile, you can refer to Smile as "current application" :
  69. ----------------------------
  70. tell current application to msg("So far, so good.")
  71. ----------------------------
  72.  
  73. ========================================================
  74.